﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	TemplateSource.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;

namespace Smart.Common.Templates
{
	/// <summary>
	/// Template source
	/// </summary>
	public abstract class TemplateSource
	{
		/// <summary>
		/// Template context
		/// </summary>
		public TemplateCtx Ctx { get; set; }

		/// <summary>
		/// Template source
		/// </summary>
		protected TemplateSource(TemplateCtx ctx)
		{
			Ctx = ctx;
		}

		/// <summary>
		/// Create new template filter
		/// </summary>
		public abstract TemplateFilter CreateFilter();

		/// <summary>
		/// Load list of available templates, using filter
		/// </summary>
		/// <param name="filter">filter</param>
		/// <returns>List of templates (not null, but can be empty)</returns>
		public abstract IList<ITemplate> LoadTemplates(TemplateFilter filter);

		/// <summary>
		/// Load specified template
		/// </summary>
		/// <param name="templateId">template identity</param>
		/// <returns>Template or null</returns>
		public abstract ITemplate LoadTemplate(string templateId);

		/// <summary>
		/// Create new instance
		/// </summary>
		/// <param name="instanceId">instance identity</param>
		/// <param name="template">source template</param>
		/// <returns>Instance or null</returns>
		public abstract ITemplateInstance CreateInstance(string instanceId, ITemplate template);

		/// <summary>
		/// Load template data from 
		/// </summary>
		public virtual object LoadTemplateData(ITemplate template)
		{
			return template.Data;
		}
	}
}